package com.aldd.mapper;

import com.aldd.entity.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookMapper {
    //查所有图书
    @Select("select * from book")
    List<Book> selectAllBook();

    //根据ID查图书
    @Select("select * from book where bookId=#{id}")
    Book selectBookById(int id);

    //根据ID删除图书
    @Delete("delete from book where bookId=#{id}")
    int deleteBookById(int id);

    //添加图书
    @Insert("insert into book(bookName, bookAuthor, bookPublisher) values (#{bookName},#{bookAuthor},#{bookPublisher})")
    int insertBook(Book book);

    //修改图书
    @Update("update book set bookName=#{bookName}, bookAuthor=#{bookAuthor}, bookPublisher=#{bookPublisher} where bookId=#{bookId}")
    int updateBook(Book book);

    //根据书名查找图书
    @Select("select * from book where bookName like '%${bookName}%'")
    List<Book> selectBookByBookName(String bookName);

}
